﻿using System.Collections;
using System.Collections.Generic;
using GameFramework.Battle.Core;
using Gameplay.PVE.Entity;
using UnityEngine;

namespace Gameplay.PVE
{
    public class MoveToAttack : Havior
    {
        
        private BattleUnit unit;
        public override ETaskResult Execute(ETaskResult result,bool last)
        {
            if (unit.Data.lockTarget != null && !unit.Data.lockTarget.Data.isDead)
            {
                if (unit.Data.attackPosition == Vector3.zero)
                {
                    unit.Data.SetTargetPosition(unit.Data.lockTarget.Data.position);
                }
                else
                {
                    unit.Data.SetTargetPosition(unit.Data.attackPosition);
                }

            }
            //Debug.LogError("moveToAttack");
            return ETaskResult.Successed;
        }

        public override void Parse(Dictionary<string, object> data)
        {
           
        }

        public override void SharedVariableChanged(string key, object value)
        {
            if (key == ESharedVariablesType.Executor)
            {
                unit = (BattleUnit) value;
            }
        }
    }

}
